package com.blast.sspai.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;

import com.blast.sspai.R;
import com.blast.sspai.util.ClearCacheUtil;

import java.io.File;

/**
 * author : hg
 * email: 530157892@qq.com
 * 15/6/15.
 */

/**
 * 设置界面
 */
public class SettingsActivity extends Activity {
    TextView cache;
    private TextView versionTV;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_settings);

        versionTV = (TextView) findViewById(R.id.version);

        cache = (TextView) findViewById(R.id.cache_size);
        File cacheFile = this.getCacheDir();
        try {
            String cacheStr = ClearCacheUtil.getCacheSize(cacheFile);
            Log.d("---------->",""+cacheStr);
            cache.setText(cacheStr);
        } catch (Exception e) {
            e.printStackTrace();
        }

        //找不到焦点。。。。。
        /*LinearLayout layout = (LinearLayout) findViewById(R.id.settings);
        layout.setOnClickListener(this);*/
    }

    /*@Override
    public void onClick(View view) {
        int click = view.getId();
        switch (click){
            case R.id.push_notification:
                break;
            case R.id.clear_cache:
                break;
            case R.id.check_version:
                break;
            case R.id.choose_type:
                break;
            case R.id.feedback:
                Intent fbIntent = new Intent(this, FeedbackActivity.class);
                startActivity(fbIntent);
                break;
            case R.id.about_me:
                Intent aMIntent = new Intent(this, AboutMeActivity.class);
                startActivity(aMIntent);
                break;
        }
    }
*/
    /**
     * 点击返回
     * @param view
     */
    public void backOnClick(View view) {
        finish();
    }


    /**
     * 推送通知
     * @param view
     */
    public void pnOnClick(View view) {

    }

    /**
     * 清理缓存
     * @param view
     */
    public void ccOnClick(View view) {
        ClearCacheUtil.cleanInternalCache(getApplicationContext());

        File ccacheFile = this.getCacheDir();
        try {
            String ccacheStr = ClearCacheUtil.getCacheSize(ccacheFile);
            cache.setText(ccacheStr);
            Log.d("---------->",""+ccacheStr);
            Toast.makeText(this, "清除成功", Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            e.printStackTrace();
        }
        //cache.setText("0B");
        //Toast.makeText(this, "清除成功", Toast.LENGTH_LONG).show();
    }

    /**
     * 检查新版本
     * @param view
     */
    public void cvOnClick(View view) {
        SharedPreferences sharedPreferences = getSharedPreferences(getPackageName(), MODE_PRIVATE);
        String version = sharedPreferences.getString("version", ""+1);
        versionTV.setText("V " + version);
        Toast.makeText(this, "最新版本", Toast.LENGTH_LONG).show();
    }

    /**
     * 选择主题
     * @param view
     */
    public void ctOnClick(View view) {

    }

    /**
     * 意见反馈
     * @param view
     */
    public void fbOnClick(View view) {
        Intent fbIntent = new Intent(this, FeedbackActivity.class);
        startActivity(fbIntent);
    }

    /**
     * 关于我们
     * @param view
     */
    public void amOnClick(View view) {
        Intent aMIntent = new Intent(this, AboutMeActivity.class);
        startActivity(aMIntent);
    }
}